{% extends 'base.html' %}

{% block title %}
  CalPortal - {{user}}
{% endblock %}

{% block scripts %}
<script src='/static/index.js'></script>
<script type = "text/javascript">

  function enable_disable(id)
	{
	var bool = document.getElementById("id_item_"+id).disabled
	document.getElementById("id_item_"+id).disabled = !bool;
	document.getElementById("submit_item_"+id).disabled = !bool;
	}
</script>

{% endblock %}

{% block navi %}
  <div id='classes'>
    <p><h2><a href='/classes'>Classes</a></h2></p>
    <ul class='class_head'>
    {% for section in sections %}
      <li class='class_list' id='{{section}}'>{{section.classes}}</li>
    {% endfor %}
    </ul>
  </div>
{% endblock %}

{% block content %}
  <form method='POST' action='/'>
    <div id='new_assign'>
      <div>
        <div class='add_assignment_left left'>Assignment Name:</div>
        <div class='add_assignment_right left'>{{add_new.title}}</div>
        <div class='add_assignment_left left'>Due:</div>
        <div class='add_assignment_right left'><input type="text" name="due" id="datepicker"></div>
      </div>
      <div class='main_clear'></div>
      <div>
        <div class='add_assignment_left left'>Type</div>
        <div class='add_assignment_right left'>{{add_new.item_type}}</div>
        <div class='add_assignment_left left'>Section</div>
        <div class='add_assignment_right left'>
          <select name="section" id="id_section">
            <option value="">--------</option>
            {% for section in sections %}
              <option value="{{section.key}}">{{section.classes}}</option>
            {% endfor %}
          </select>
        </div>
      </div>
      <div class='main_clear'></div>
      <div class='add_assignment_left'>
        <input type='submit' value='add'>
      </div>
    <div class="clear"></div>
    </div>
    <div class='main_clear'></div>


  </form>
  {% for item, comments in items %}
    <div class='item_container'>
      <div class='item_header'>
        <div class='item_class'><h4>{{item.section.classes}}<h4></div>
        <div class='item_title'><h4>{{item.title}}</h4></div>
        <div style='padding:3px;margin:0px;' class='right'>{% if item.created_by.nickname == user %}
          <a href='/remove_item/{{item.key}}'>Delete</a>
        {% endif %}</div>
        <div class='item_date {% if item.soon %}soon{% endif %}'>{{item.due}}</div>
        <div class='clear'></div>
        <div class='left'>Posted by: {{item.created_by.nickname}}</div>
        <div class='clear'></div>
        <div class='left'>Last Edited by: {{item.last_editor.nickname}}</div>
        <div class='clear'></div>
      </div>
      <div class='item_resource'>
        <FORM action="update_resource" method="POST" name="resource">
        <INPUT type="hidden" name="item_id" value="{{item.key}}">
        <textarea name="resource" id="id_item_{{item.key}}" style="width:600px;height:60px" disabled="true">{{item.resource}}</textarea>
		<input type="checkbox" name="edit" value="edit" onclick="enable_disable('{{item.key}}')">Edit 
        <INPUT type="submit" id="submit_item_{{item.key}}" disabled="true" name="submit" value="Update">
        </FORM>
      </div>
      <div class='item_comments'>
        {% for comment,thumbAction in comments %}
          <div class='item_comment_{% cycle 'odd' 'even' %}'>
            <div class='comment'>
              <div class='left'>
                <p class='comment_name'>{{comment.created_by.nickname}} said...</p>
              </div>
              <div>
                <p class='comment_date'>{{comment.datetime}}</p>
              </div>
              <div class="clear"></div>
              <p class='comment_content'>{{comment.content}}</p>
            </div>
            <div class='comment_info'>
              <ul style="margin:0px;padding:0px;">
                <li>
                  <a href='/thumbs_up/{{comment.key}}'><IMG SRC='/../static/images/thumb-up.png'></a>
                  {% if thumbAction > 0 %}
                    <B>
                  {% endif %}
                  ({{comment.thumbs_up_count}})
                  {% if thumbAction > 0 %}
                    </B>
                  {% endif %}
                </li>
                <li>
                  <a href='/thumbs_down/{{comment.key}}'><IMG SRC='/../static/images/thumb-down.png'></a>
                  {% if thumbAction < 0 %}
                    <B>
                  {% endif %}
                  ({{comment.thumbs_down_count}})
                  {% if thumbAction < 0 %}
                    </B>
                  {% endif %}
                </li>
                <li>{% if comment.created_by.nickname == user %}
                <a href='/remove_comment/{{comment.key}}'>Delete</a>
                {% endif %}</li>
              </ul>
            </div>
          </div>
        {% endfor %}
        <div class='item_comment'>
          <div class='comment'>
            <form action='/add_comment' method='POST'>
              <input type='hidden' name='item_key' value='{{item.key}}'>
              <span class='comment_name'>{{user}} says...</span>
              <textarea class="textarea_content" rows="3" cols="40" name="content"></textarea>
              <input type='submit' value='Add comment'>
            </form>
          </div>
        </div>
      </div>
    </div>
  {% endfor %}
{% endblock %}